﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using _1Dot9MasterBiz;
using System.Collections;

public partial class Gallery : System.Web.UI.Page
{
    /// <summary>
    /// work item 을 담는 맵버변수
    /// </summary>
    DataSet gdsPrj = null;
    DataSet gdsWrok = null;

    /// <summary>
    /// 페이지 로드
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        gdsPrj = this.GetWorkItem("001");
        gdsWrok = this.GetWorkItem("002");
        innerProjectContent.InnerHtml = WriteInnerHtml(gdsPrj, "project.png");
        innerWorkContent.InnerHtml = WriteInnerHtml(gdsWrok, "work.png"); 
    }

    /// <summary>
    /// 화면에 innerHtml을 동적 구성한다.
    /// </summary>
    public string WriteInnerHtml(DataSet ds, string iconNm)
    {
        if (ds.Tables[0].Rows.Count < 1)
            return "<br />";

        StringBuilder inner = new StringBuilder();
        string fileNm = "";

        inner.Append("<img src=\"Image/gallery/" + iconNm + "\" alt=\"\" /><br />");
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            fileNm = ds.Tables[0].Rows[i]["GUID"].ToString() + ds.Tables[0].Rows[0]["EXTENTION"].ToString();
            inner.Append("<a class=\"fancybox-buttons\" data-fancybox-group=\"button\" href=\"");
            inner.Append("Files/" + fileNm);
            inner.Append("\" title=\"" + ds.Tables[0].Rows[i]["NOTE"].ToString() + "\" ><img src=\"");
            inner.Append("Files/icons/" + fileNm);
            inner.Append("\" class=\"image_rollover\" alt=\"\"/></a>");
            if (i > 0 && (i+1) % 10 == 0)
                inner.Append("<br /><br />");
            else
                inner.Append("&nbsp;&nbsp;");
        }

        return inner.ToString();
    }

    /// <summary>
    ///  work item 리스트를 DB에서 조회한다.
    /// </summary>
    public DataSet GetWorkItem(string _type)
    {
        DataSet ds = new DataSet();
        try
        {
            using (WorkBiz workBiz = new WorkBiz())
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("@P_USE_YN", true);
                htParams.Add("@P_TYPE", _type); // 001 project , 002 work

                ds = workBiz.GetWorkItem(htParams);
            }
        }
        catch(Exception ex)
        {            
            Response.Write("<script> alert('" + ex.Message.ToString() + "'); </script>");
        }

        return ds;
    }
}
